//
//  SeeViewController.m
//  Zaker
//
//  Created by 赵磊 on 16/3/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SeeViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <View+MASAdditions.h>
#import "SeeKindViewController.h"
#import "SeeVideoDetailViewController.h"
#import "SeeButtonViewController.h"

@interface SeeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,shareDelegate>
{
    enum WXScene _scene;
}

@property(nonatomic, strong)UICollectionView *bottomCollectionView; //底部基础视图
@property(nonatomic ,strong)UIView *redView;

@property(nonatomic, strong)UICollectionView *collection;

@end


@implementation SeeViewController

-(void)viewWillDisappear:(BOOL)animated
{
    [self.redView removeFromSuperview];
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar addSubview:self.redView];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
       [self bottomView];
//    UIBarButtonItem *left =[[UIBarButtonItem alloc] initWithTitle:@"视频" style:UIBarButtonItemStylePlain target:self action:@selector(shipinAction:)];
//    UIBarButtonItem *left1 =[[ UIBarButtonItem alloc] initWithTitle:@"电台" style:UIBarButtonItemStylePlain target:self action:@selector(diantaiAction:)];
//    self.navigationItem.leftBarButtonItems = @[left,left1];
    
    
    UIButton *left = [ UIButton buttonWithType: UIButtonTypeCustom];
    [left setTitle:@"视频" forState:UIControlStateNormal];
     
     left.frame = CGRectMake(WIDTH *10, 0, 50*WIDTH, 50*HEIGHT);
    [left addTarget:self action:@selector(shipinAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftbar = [[UIBarButtonItem alloc]initWithCustomView:left];

    
    UIButton *left1 = [ UIButton buttonWithType: UIButtonTypeCustom];
    [left1 setTitle:@"电台" forState:UIControlStateNormal];
    
    left1.frame = CGRectMake(WIDTH *40, 0, 50*WIDTH, 50*HEIGHT);
    [left1 addTarget:self action:@selector(diantaiAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftbar1 = [[UIBarButtonItem alloc]initWithCustomView:left1];
     self.navigationItem.leftBarButtonItems = @[leftbar,leftbar1];

    
    self.redView = [[UIView alloc] initWithFrame:CGRectMake(10 * WIDTH, 46 * HEIGHT, 60* WIDTH, 3*HEIGHT)];
    self.redView.backgroundColor =[ UIColor whiteColor];
    [self.view addSubview:self.redView];
    left.tintColor = [UIColor whiteColor];
    left1.tintColor = [ UIColor whiteColor];
      }

-(void)shipinAction:(UIBarButtonItem *)shipin
{
    [_bottomCollectionView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.redView .frame = CGRectMake(10* WIDTH, 46 * HEIGHT, 60 * WIDTH, 3*HEIGHT);
        
    }];
    

}
-(void)diantaiAction:(UIBarButtonItem *)diantai
{
    [_bottomCollectionView setContentOffset:CGPointMake(WIDTH * 375,0) animated:YES];
    [UIView animateWithDuration:0.3 animations:^{
        self.redView .frame = CGRectMake(70 * WIDTH, 46 * HEIGHT, 45 * WIDTH, 3*HEIGHT);
        
    }];

}
//创建底部视图
-(void)bottomView
{
    UICollectionViewFlowLayout *layout =[[ UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.itemSize = CGSizeMake(WIDTH * 375   , HEIGHT * 667);
    self.bottomCollectionView =[[ UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH * 375 , HEIGHT * 667) collectionViewLayout:layout];
    /**注册视频cell*/
   [ _bottomCollectionView registerClass:[SeeBottomCollectCell1 class] forCellWithReuseIdentifier:@"bottomcell1"];
    /**注册电台cell*/
    [_bottomCollectionView registerClass:[SeeBottomCollectCell2 class] forCellWithReuseIdentifier:@"bottomcell2"];
    _bottomCollectionView.dataSource = self;
    _bottomCollectionView.delegate = self;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _bottomCollectionView.pagingEnabled = YES;
    _bottomCollectionView.backgroundColor = [ UIColor whiteColor];
    [self.view addSubview:_bottomCollectionView];
    
}
#pragma mark -item个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}
#pragma mark -cell设置
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    if (indexPath.item == 0) {
    
        SeeBottomCollectCell1 *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"bottomcell1" forIndexPath:indexPath];
       /**头部block 方法*/
        BLOCK push = ^(NSString *str)
        {   SeeKindViewController *kind = [[ SeeKindViewController alloc] init];
            kind.sid = str;
            [self.navigationController pushViewController:kind animated:YES];
            
        };
        cell.pushBlock = push;
       /**tableView点击跳转*/
       BLOCK1 tablePush = ^(SeeModel *model)
        {
            SeeVideoDetailViewController *seeVideo =[[ SeeVideoDetailViewController alloc] init];
            seeVideo.sModel = model;
            [self.navigationController pushViewController:seeVideo animated:YES];
        };
        cell.pushTableBlock = tablePush;
        /**分享的协议*/
        cell.sdelegate = self;
        return cell;
    }
    else if (indexPath.item == 1)
    {
        SeeBottomCollectCell2 *cell =[ collectionView dequeueReusableCellWithReuseIdentifier:@"bottomcell2" forIndexPath:indexPath];
        RBlOCK radioButton = ^(NSString *str)
        {
            SeeButtonViewController *buttonVC =[[ SeeButtonViewController alloc] init];
            buttonVC.string = str;
            [self.navigationController pushViewController:buttonVC animated:YES];
        };
        cell.btnClick = radioButton;
        
        ColBLOCK collect = ^(NSString *string)
        {
            SeeRadioViewController *radioVC =[[ SeeRadioViewController alloc] init];
            radioVC.tidString = string;
            [self.navigationController pushViewController:radioVC animated:YES];
        };
        cell.collectionblock = collect;
        return cell;
    }
    
    return nil;
}

-(void)shareWithurl:(NSString *)url
{
    NSLog(@"分享了");
    
    [Elastic elastic:url];
    

    
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x == WIDTH * 375) {
    
    [UIView animateWithDuration:0.3 animations:^{
        self.redView .frame = CGRectMake(70 * WIDTH, 43 * HEIGHT, 60 * WIDTH, 3 * HEIGHT);
    
    }];
    }
     if (scrollView.contentOffset.x == 0)
    { [UIView animateWithDuration:0.3 animations:^{
        self.redView .frame = CGRectMake(10, 43 * HEIGHT, 60 * WIDTH, 3 * HEIGHT);
        
    }];
    
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
